﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.LIB;
using YArchitech.Revit;

namespace YArchitech.Temp
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	public class Command : IExternalCommand
	{
		public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{
			List<ViewType> viewTypes = YJKRevitTools.ListViewNeed(2);
			if (!YJKRevitTools.ViewCheck(commandData.Application.ActiveUIDocument, viewTypes))
			{
				return Autodesk.Revit.UI.Result.Cancelled;
			}
			try
			{
				IntPtr mainWindowHandle = Process.GetCurrentProcess().MainWindowHandle;
				Helper helper = new Helper();
				helper.RevitHandle = mainWindowHandle;
				helper.CommandData = commandData;
				helper.SearchBranch();
				Product.Init();
				HYDataAccess.DataFolder = Product.UserDataLocation;
				HYDataAccess.Init(false);
				helper.ShowMainForm(true);
			}
			catch (Exception ex)
			{
				message = ex.Message;
			}
			return Autodesk.Revit.UI.Result.Succeeded;
		}
	}
}
